package com.jxb.netty.network.bio;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class ServerTask implements Runnable {
    private Socket socket = null;
    public ServerTask(Socket socket){
        this.socket = socket;
    }


    @Override
    public void run() {
        System.out.println("accept client socket ....");
        try (ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
             ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream())){
            //服务端的输入
            String msg = objectInputStream.readUTF();
            System.out.println("Accept client message:"+msg);
            //客户端的输入
            objectOutputStream.writeUTF("Hello,"+msg);
            objectOutputStream.flush();
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
